//
//  HWTakeVc.m
//  JWC
//
//  Created by lanou on 16/4/18.
//  Copyright © 2016年 陈帅. All rights reserved.
//

#import "HWTakeVc.h"
#import "HWTakeModel.h"
#import "HWTakeTableViewCell.h"
#import "HWConcernTool.h"
#import "HWTakeDetailVc.h"

@interface HWTakeVc ()

@property (nonatomic, strong)HWConcernTool *tool;

@property (nonatomic, strong)NSArray *modelArray;

@end

static NSString *cellID = @"take";
@implementation HWTakeVc

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"推荐订阅";
    [self.tableView registerNib:[UINib nibWithNibName:@"HWTakeTableViewCell" bundle:nil] forCellReuseIdentifier:cellID];
    
    [self getData];
}

#pragma mark --- 加载数据 ---
- (void)getData
{
    [self.tool getTakeDatablock:^(id json) {
        self.modelArray = json;
        [self.tableView reloadData];
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.modelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWTakeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    cell.model = self.modelArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWTakeDetailVc *detailVc = [[HWTakeDetailVc alloc]init];
    detailVc.takeModel = self.modelArray[indexPath.row];
    [self.navigationController pushViewController:detailVc animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

- (HWConcernTool *)tool
{
    if (_tool == nil)
    {
        _tool = [[HWConcernTool alloc]init];
    }
    return _tool;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
